package com.intct.hbase.ddl.table;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

/**
 * @author gufg
 * @since 2025-08-06 09:29
 */
public class DropTable {
    public static void main(String[] args) throws IOException {
        // 创建HBase连接
        Connection connection = ConnectionFactory.createConnection();

        // 获取Admin实例
        Admin admin = connection.getAdmin();

        // 判断表存在
        TableName tablName = TableName.valueOf("intct83", "t5_api");
        try {
            if (admin.tableExists(tablName)) {
                // 判断表未禁用
                if (!admin.isTableDisabled(tablName)) {
                    // 禁用表
                    admin.disableTable(tablName);
                }

                // 删除表
                admin.deleteTable(tablName);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭资源
            if (admin != null) {
                admin.close();
            }
            if (connection != null) {
                connection.close();
            }
        }

    }
}
